package com.study.studyelasticsearch.client.highLevelClient;

import com.study.studyelasticsearch.config.EsConfig;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

// 参考：
// 官方快速上手：https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients
// 官方使用文档：
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.8/java-rest-high-getting-started-initialization.html
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.8/java-rest-high-supported-apis.html
@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {

    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {
        // 怎么设置优先级？
        System.out.println(EsConfig.getIp());
        System.out.println(EsConfig.getHttpPort());
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
            .connectedTo("localhost:9200")
            .build();


        return RestClients.create(clientConfiguration).rest();
    }
}